<?php
	class logger {
		public static function json($v , $one = false){
			
			if($one){
				if(count($v)>=1) logger::trace(json_encode($v[0]));
			}else
				logger::trace(json_encode($v));
		} 
        public static function trace($v)
        {
			logger::process($v);
        }
        private static function process($v){
			$type = $_SERVER["HTTP_ACCEPT"];
			if(strpos($type , "/json")){
				header("Content-Type:application/json; charset=utf-8");
			}elseif(strpos($type , "/javascript")){
				header("Content-Type:text/javascript; charset=utf-8");
				if(!empty($_GET['callback'])){
					$callback = $_GET['callback'];
					$v = $callback."(".$v.")";
				}
			}
			echo($v);
			
		}
		
        public static function errorPower()
        {
            $v = '{"status":-1,"info":"power request!"}';
            logger::process($v);
        }
        
        public static function success($info)
        {
        	$v = '{"status":"0","detail":"'.$info.'"}';
			logger::process($v);
        }
        
		
		public static function error($info)
        {
        	$v = '{"status":"-1","detail":"'.$info.'"}';
			logger::process($v);
        }
    }
?>